package org.sport.dbImplement;

import org.sport.dbInterface.ParActOperation;
import org.sport.model.entityModel.ParacttableEntity;
import org.sport.model.entityModel.UsertableEntity;
import org.sport.repository.ParacttableRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Allen on 2017/9/22.
 */
@Service
public class ParActOpeImp implements ParActOperation{


    @Autowired
    ParacttableRepository   paracttableRepository;

    @Override
    public boolean addOnParAct(ParacttableEntity paracttableEntity) {
        if(paracttableRepository.saveAndFlush(paracttableEntity) == null)
            return false;
        else
            return true;
    }

    @Override
    public boolean updateOneParActStatus(ParacttableEntity paracttableEntity) {
        paracttableRepository.updateParActByActId(paracttableEntity.getStatus(),paracttableEntity.getActivitytableByActId());
        return true;
    }

    @Override
    public boolean delOneParAct(ParacttableEntity paracttableEntity) {
        if(paracttableEntity != null)
        {
            if((paracttableEntity = paracttableRepository.findOne(paracttableEntity.getId())) == null)
                System.out.println("找不到对应活动id");
            else {
                paracttableRepository.delete(paracttableEntity);
                paracttableRepository.flush();
            }
            return true;        //需要求证删除之后是否还需要查询数据
        }
        else
            return false;
    }

    @Override
    public List<ParacttableEntity>  findByUserId(UsertableEntity usertableEntity) {

        return paracttableRepository.findByUserId(usertableEntity);
    }

    @Override
    public List<ParacttableEntity> findAll() {
        return paracttableRepository.findAll();
    }
}
